//
// Created by user on 2025/7/31.
//

#ifndef HELLOC_INITIALIZATION_H
#define HELLOC_INITIALIZATION_H

#include "systemc"
#include <iostream>
using namespace std;
using namespace sc_core;

class Initialization : public sc_module {
public:
    sc_event e;
    Initialization(sc_module_name name) : sc_module(name)
    {
        SC_THREAD(trigger);
        SC_THREAD(catcher_3);
        SC_THREAD(catcher_2);
        SC_THREAD(catcher_1);
        sensitive << e;
        dont_initialize();
    }

    void trigger(){
        while(true){
            e.notify(1,SC_SEC);
            wait(2,SC_SEC);
        }
    }

    void catcher_1() {
        while (true) {
            std::cout << sc_time_stamp() << ": catcher_1 triggered" << std::endl;
            wait(e); // dynamic sensitivity
        }
    }
    void catcher_2() {
        wait(e); // avoid initialization --- mimic systemC 1.0 behavior
        while (true) {
            std::cout << sc_time_stamp() << ": catcher_2 triggered" << std::endl;
            wait(e); // dynamic sensitivity
        }
    }
    void catcher_3() { // relies on dont_initialize() to avoid initialization
        while (true) {
            std::cout << sc_time_stamp() << ": catcher_3 triggered" << std::endl;
            wait(e); // dynamic sensitivity
        }
    }
};


#endif //HELLOC_INITIALIZATION_H
